package com.machine.filling.function.set.excOrderDetail;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.machine.filling.R;
import com.machine.filling.base.BaseRecyclerAdapter;
import com.machine.filling.db.modle.ExceptionOrderModle;
import com.machine.filling.db.modle.TempOrderModle;
import com.machine.filling.util.DateUtils;
import com.machine.filling.util.StringUtil;

/**
 * Created by Administrator on 2018/2/3 0003.
 */

public class ExcOrderDetailAdapter extends BaseRecyclerAdapter<ExcOrderDetailAdapter.Holder> {


    private String[] keyNames;
    private ExceptionOrderModle bean;
    private String[] values;

    public ExcOrderDetailAdapter(Context mContext, ExceptionOrderModle bean) {
        super(mContext);
        keyNames = mContext.getResources().getStringArray(R.array.order_detail);
        values = new String[keyNames.length];
        //1.油卡类型
        if ("1".equals(bean.getOilCardType())){
            //1用户的加油卡 2员工卡
            values[0] = "用户卡";
        }else if ("2".equals(bean.getOilCardType())){
            values[0] = "员工卡";
        }else  {
            values[0] = "无卡加油";
        }
        //2.油卡编号
        values[1] = StringUtil.isNullOrEmpty(bean.getOilCardNum()) ? "无" : bean.getOilCardNum();
        //3.订单编号
        values[2] = bean.getOrderNum();
        //4.油品名称
        values[3] = bean.getOilTypeName();
        //5.油品单价
        values[4] = bean.getPrice() + "元/升";
        //6.加油数量
        values[5] = bean.getMlAmount() + "L";
        //7.优惠金额
        values[6] = bean.getDiscountPrice()== null ? "0元"  : bean.getDiscountPrice() + "元";
        //8.实付总金额
        values[7] = bean.getAmount()== null ? "0元"  : bean.getAmount() + "元";
        //9.支付状态  1未支付  2已支付未写卡  3已支付
        switch (bean.getPayState()){
            case "1":
                values[8] = "未支付";
                break;
            case "2":values[8] = "已支付未写卡";
                break;
            case "3":values[8] = "已支付";
                break;
            default:
                values[8] = "";
                break;
        }
        //10.支付方式  1支付宝 2微信 3现金 4油卡 5预约
        switch (bean.getPayMode()){
            case "1":
                values[9] = "支付宝";
                break;
            case "2":
                values[9] = "微信";
                break;
            case "3":
                values[9] = "现金";
                break;
            case "4":
                values[9] = "油卡";
                break;
            case "5":
                values[9] = "线上预约";
                break;
            default:
                values[9] = "未知";
                break;
        }

        //11.加油时间
        values[10] = DateUtils.formatDateTimeYMDHMS(bean.getCreateD());
        //12.上传状态  0 未上传 1已上传
        if ("0".equals(bean.getUploadState())){
            values[11] = "未上传";
        }else if ("1".equals(bean.getUploadState())){
            values[11] = "已上传";
        }else {
            values[11] = "未知";
        }
        //13.原因
        values[12] = ("1".equals(bean.getUploadState()) && "3".equals(bean.getPayState())) ? "" : bean.getReason();
    }

    @Override
    public ExcOrderDetailAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_order_detail, parent, false);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        holder.tv_key_name.setText(keyNames[position]);
        holder.tv_value.setText(values[position]);

        if (position == 12 && "".equals(values[position])){
            //上传失败原因
            holder.tv_key_name.setVisibility(View.GONE);
            holder.tv_value.setVisibility(View.GONE);
        }else {
            holder.tv_key_name.setVisibility(View.VISIBLE);
            holder.tv_value.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return keyNames.length;
    }

    public class Holder extends RecyclerView.ViewHolder {

        private final TextView tv_key_name;
        private final TextView tv_value;

        public Holder(View itemView) {
            super(itemView);
            tv_key_name = (TextView) itemView.findViewById(R.id.tv_key_name);
            tv_value = (TextView) itemView.findViewById(R.id.tv_value);
        }
    }

}
